import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class C_1568 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Mo> list = new ArrayList<>();
        String temp = sc.next();
        list.add(new Mo(Integer.parseInt(temp.substring(6,14)),Double.parseDouble(temp)));
        for (int i = 1; i < n; i++) {
            String str = sc.next();
            int year = Integer.parseInt(str.substring(6,14));
            double no = Double.parseDouble(str);
            for (int j = 0; j < list.size(); j++) {
                if (j==0&&year>list.get(0).year){
                    list.add(0,new Mo(year,no));
                    break;
                }
                else if(j==0&&list.get(0).year==year&&list.get(0).no>no){
                    list.add(0,new Mo(year,no));
                    break;
                }else if (j==0) continue;

                if (list.get(j-1).year<year&&list.get(j).year>year){
                    list.add(j,new Mo(year,no));
                    break;
                }else if(list.get(j).year==year&&list.get(j).no>no&&(list.get(j-1).year<year||(list.get(j-1).year==year&&list.get(j-1).no<no))){
                    list.add(j,new Mo(year,no));
                    break;
                }else if (list.get(j-1).year==year&&list.get(j-1).no<no&&(list.get(j).year>year||(list.get(j).year==year&&list.get(j).no>no))){
                    list.add(j,new Mo(year,no));
                    break;
                }
                if (j==list.size()-1&&list.get(list.size()-1).year>year){
                    list.add(new Mo(year,no));
                    break;
                }else if (j==list.size()-1){
                    list.add(list.size()-1,new Mo(year,no));
                    break;
                }

            }
        }
        for (Mo mo : list) {
            System.out.println(mo.no);
        }
    }
}
class Mo{
    int year;
    double no;

    public Mo(int year, double no) {
        this.year = year;
        this.no = no;
    }
}

